package com.example.kotlindemo

import java.io.File

/**
 *@time : 2020/3/24
 *@author :muzi102
 *@Description
 */

fun main(args: Array<String>) {
//    var name = "康老师"
//    println("$name,很厉害")
//
//    var a: String? = "ABC"
//    a = null
//
//    var xiaomo = student("小莫", 12)
//    println("学生：${xiaomo.name} , 年龄 : ${xiaomo.age}")
//    var name_my:String?=null
    val test = "Hello world !"

//    println(strlen(test))
//    println("userName is ${User.userName}")
//    println("userName is ${User.password}")

//    var xiaoming = Student("xiaoming", 7)
//    xiaoming.age = 23
//    xiaoming.name = "laowang"
//    println(xiaoming.toString())
//    println(xiaoming.hashCode())

//    listTest()
//    wathis(3)
//    wathis(34.3f)
//    wathis("ad")
//    nullandelse()
    forEach()
}

fun strlen(test: Any): Any? {
    if (test is String) {
        return test.length;
    } else if (test is Number) {
        return test.toString().length
    } else if (test is Boolean) {
        return 1
    }
    println("Not A String ")
    return -1
}


data class Student(var name: String, var age: Int) {
    override fun toString(): String {
        return "Student(name='$name', age=$age)"
    }

    override fun equals(other: Any?): Boolean {
        return super.equals(other)
    }

    override fun hashCode(): Int {
        return super.hashCode()
    }
}


fun listTest() {
    val list = listOf("1", "2", "3", "4", "5")
    if ("1" in list) println("list contain 1")
    val nameMap = mapOf<String, Int>("小莫" to 0, "沈阳" to 1, "蔡哥" to 2)
}

object User {
    val userName = "小莫"
    val password = "123456"
}

fun wathis(any: Any) {
    when (any) {
        is Int -> println("any is an Int")
        is Float -> println("any is a float")
        else -> println("I don't know what is any")
    }
}

fun nullandelse() {
    val files = File("Test").listFiles()
    println(files?.size ?: "empty")
}

fun forEach() {
    for (i in 0 until 500) {
        println(" i is $i")
        Thread.sleep(10)
    }
}


open class Fruits(val price: Float) {}

class Apple(val p: Float) : Fruits(p) {

}

class Banana(val myPrice: Float) : Fruits(myPrice) {}